package net.maku.events.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.events.convert.ActivityBriskWalkSiteAnswerConfigConvert;
import net.maku.events.entity.ActivityBriskWalkSiteAnswerConfigEntity;
import net.maku.events.query.ActivityBriskWalkSiteAnswerConfigQuery;
import net.maku.events.vo.ActivityBriskWalkSiteAnswerConfigVO;
import net.maku.events.dao.ActivityBriskWalkSiteAnswerConfigDao;
import net.maku.events.service.ActivityBriskWalkSiteAnswerConfigService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 健步走活动站点竞赛答题配置
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-22
 */
@Service
@AllArgsConstructor
public class ActivityBriskWalkSiteAnswerConfigServiceImpl extends BaseServiceImpl<ActivityBriskWalkSiteAnswerConfigDao, ActivityBriskWalkSiteAnswerConfigEntity> implements ActivityBriskWalkSiteAnswerConfigService {

    @Override
    public PageResult<ActivityBriskWalkSiteAnswerConfigVO> page(ActivityBriskWalkSiteAnswerConfigQuery query) {
        IPage<ActivityBriskWalkSiteAnswerConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(ActivityBriskWalkSiteAnswerConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<ActivityBriskWalkSiteAnswerConfigEntity> getWrapper(ActivityBriskWalkSiteAnswerConfigQuery query){
        LambdaQueryWrapper<ActivityBriskWalkSiteAnswerConfigEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(ActivityBriskWalkSiteAnswerConfigVO vo) {
        ActivityBriskWalkSiteAnswerConfigEntity entity = ActivityBriskWalkSiteAnswerConfigConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(ActivityBriskWalkSiteAnswerConfigVO vo) {
        ActivityBriskWalkSiteAnswerConfigEntity entity = ActivityBriskWalkSiteAnswerConfigConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}